package com.doge.walknovel.business.novel.widgets

import android.content.Context
import android.util.AttributeSet
import android.view.LayoutInflater
import androidx.constraintlayout.widget.ConstraintLayout
import com.doge.wnpro.R
import com.doge.walknovel.api.model.NovelInfo
import com.doge.wnpro.databinding.ViewMightLikeNovelBinding
import com.doge.walknovel.utils.RoundedCorners8
import com.doge.walknovel.utils.dp
import com.doge.walknovel.utils.load
import com.doge.walknovel.utils.setOnClickCallback

class MightLikeNovelView @JvmOverloads constructor(
    context: Context,
    attrs: AttributeSet? = null
) : ConstraintLayout(context, attrs) {
    private val binding =
        ViewMightLikeNovelBinding.inflate(LayoutInflater.from(context), this)

    private var listener: OnClickListener? = null

    init {
        binding.likeNovelName.setOnClickCallback { listener?.onClick(this) }
        binding.likeAuthor.setOnClickCallback { listener?.onClick(this) }
        binding.item.setOnClickCallback { listener?.onClick(this) }
    }

    fun set(data: NovelInfo) {
        binding.likeCover.load(
            data.coverUrl,
            R.drawable.shape_f7f7f7_8,
            transformation = RoundedCorners8,
            width = 132.dp,
            height = 188.dp,
        )
        binding.likeNovelName.text = data.title
        binding.likeAuthor.text = data.author
    }

    override fun setOnClickListener(l: OnClickListener?) {
        listener = l
    }
}